package com.hanxiaozhang.system.dao;

import com.hanxiaozhang.system.entity.RoleMenuEntity;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 角色菜单关联表
 *
 * @author hanxiaozhang
 * @email hanxiaozhang2018@sina.com
 * @date 2021-03-31
 */
@Mapper
public interface RoleMenuDao {

	RoleMenuEntity get(Long roleMenuId);
	
	List<RoleMenuEntity> list(Map<String, Object> map);

	int save(RoleMenuEntity roleMenu);
	
	int update(RoleMenuEntity roleMenu);

	int batchSave(List<RoleMenuEntity> roleMenus);


	/**
	 * 通过菜单id查询
	 *
	 * @param menuId
	 * @return
	 */
	@Select("SELECT * FROM sys_role_menu WHERE menu_id = #{menuId} AND  del_flag=0")
	List<RoleMenuEntity> listByMenuId(@Param("menuId") Long menuId);

	/**
	 * 通过角色id查询
	 *
	 * @param roleId
	 * @return
	 */
	@Select("SELECT * FROM sys_role_menu WHERE role_id = #{roleId} AND  del_flag=0")
	List<RoleMenuEntity> listByRoleId(@Param("roleId") Long roleId);

	/**
	 * 通过菜单id集合查询
	 *
	 * @param menuIds
	 * @return
	 */
	List<RoleMenuEntity> listByMenuIds(@Param("menuIds") List<Long> menuIds);

	/**
	 * 通过角色id集合查询
	 *
	 * @param roleIds
	 * @return
	 */
	List<RoleMenuEntity> listByRoleIds(@Param("roleIds") List<Long> roleIds);


	/**
	 * 通过角色id删除
	 *
	 * @param roleId
	 * @return
	 */
	@Update("UPDATE sys_role_menu SET del_flag = 1  WHERE role_id = #{roleId} AND  del_flag = 0")
	int removeByRoleId(@Param("roleId") Long roleId);


	/**
	 * 通过角色id集合批量删除
	 *
	 * @param roleIds
	 * @return
	 */
	int batchRemoveByRoleIds(Long[] roleIds);



}
